package demo.controller;


import demo.Constants.PermissionConstant;
import demo.annotation.RequiredPermissions;
import demo.entity.employees;
import demo.entity.managers;
import demo.entity.record;

import demo.service.CommonService;
import org.apache.log4j.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(path="/common")
public class CommonController {
    private Logger logger = Logger.getLogger(CommonController.class);

	@Autowired
    private CommonService commonService;

    @GetMapping("/getInfo") //查询个人信息
    @RequiredPermissions(PermissionConstant.COMMON)
    employees getInfo(@RequestParam(value = "emp_id")int emp_id) {
        logger.info(": 查询工号为 " + emp_id + " 的员工信息");
        return commonService.getInfo(emp_id);
    }
    @PostMapping("/user_on_work")  //员工上班打卡
    @RequiredPermissions(PermissionConstant.COMMON)
    record on_workers(@RequestParam(value = "emp_id") int emp_id){
        logger.info("：工号为 " + emp_id + " 的员工上班打卡");
        return commonService.sign_on_work(emp_id);
    }
    @PostMapping("/user_off_work")  //员工下班打卡
    @RequiredPermissions(PermissionConstant.COMMON)
    record off_workers(@RequestParam(value = "emp_id") int emp_id){
        logger.info("：工号为 " + emp_id + " 的员工下班打卡");
        return commonService.sign_off_work(emp_id);
    }
    @GetMapping("/queryRecord") //查询打卡记录
    @RequiredPermissions(PermissionConstant.COMMON)
    List<record> queryRecord(@RequestParam(value = "emp_id")int emp_id) {
        logger.info("：查询工号为 " + emp_id + " 的员工的打卡记录");
        return commonService.queryRecord(emp_id);
    }
    @PostMapping("/addManagers")  //提交请假申请
    @RequiredPermissions(PermissionConstant.COMMON)
    managers addManagers(@RequestBody managers man) {
        int emp_id = man.getEmp_id();
        logger.info("：工号为 " + emp_id + " 的员工提交请假申请");
        return commonService.addManagers(man);
    }
    @GetMapping("/queryManagers") //查询请假申请
    @RequiredPermissions(PermissionConstant.COMMON)
    List<managers> queryManagers(@RequestParam(value = "emp_id")int emp_id) {
        logger.info("：查询工号为 " + emp_id + " 的员工的请假申请");
        return commonService.queryManagers(emp_id);
    }

}
